#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>


int main()
{
        int fd = open("log.txt", O_RDONLY);
        dup2(fd, 0);
        char buffer[1024];
        while(1)
        {
               char* s =  fgets(buffer, sizeof(buffer), stdin);// stdin --> FILE* --> _filename
               if(s == NULL) break;
               printf("file content: %s", buffer);
        }
        return 0;
}

//int main()
//{
//        int fd = open("log.txt", O_WRONLY|O_CREAT|O_TRUNC, 06666);
//        dup2(fd, 1);
//        printf("dup2 dup2\n");
//        return 0;
//}


//int main()
//{
//        close(1);
//        
//        open("log.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666);
//        printf("hello printf\n");
//        fprintf(stdout, "hello fprintf\n");
//        return 0;
//}
//int main()
//{
//        close(0);
//        open("log.txt", O_RDONLY);
//        int a = 0;
//        scanf("%d", &a);
//        printf("%d\n", a);
//        return 0;
//}


        //close(1);
        //printf("%d\n", fd);

        //if(fd == -1){
        //perror("open");
        //return 1;
        //}

        //int count = 5;
        //const char *msg = "hello system append\n";
        //int len = strlen(msg);
        //while(count--)
        //{
        //write(fd, msg, len);//长度不要加\n的长度
        //}

        //close(fd);
       // return 0;
//var}
